import { generateHighlightNodeForSalePrice } from '@/utils/bizUtils';

// 最大可编辑数量限制
export const MAX_EDIT_LIMITS = 1000

// 操作类型
export const OPTION_TYPES = {
  Edit: '1', // 编辑
  Delete: '2' // 删除
}

// 操作类型下拉集合
export const OPTION_TYPES_OPTIONS = [
  {
    label: '编辑',
    value: OPTION_TYPES.Edit
  },
  {
    label: '删除',
    value: OPTION_TYPES.Delete
  },
]

// 售卖限制类型集合
export const SALE_RESTRICT_OPTIONS = [
  {
    value: '1',
    label: '不低于起售量'
  },
  {
    value: '2',
    label: '起售量整数倍'
  }
]

export const ERROR_MSG_COL = {
  title: '禁止提交原因',
  key: 'errorMessage',
  fixed: 'left',
  width: '130',
  sortable: true,
  errorTip: true,
  notShowTip: true,
}

export const BASIC_TABLE_COLUMNS = [
  {
    title: 'SKU编码',
    key: 'skuNo'
  },
  {
    title: '商品名称',
    key: 'productName'
  },
  {
    title: '规格',
    key: 'spec'
  },
  {
    title: '计量单位',
    key: 'unitName'
  },
  {
    title: '数量小数位',
    key: 'unitDecimal'
  },
  {
    title: '省',
    key: 'provinceName'
  },
]

// 可编辑表列
export const EDIT_TABLE_COLUMNS = [
  ...BASIC_TABLE_COLUMNS,
  {
    title: '最小起售量',
    children: [
      { title: '原值', key: 'saleMinOld' },
      {
        title: '现值',
        width: 160,
        key: 'saleMin',
        type: 'inputNumChange',
        size: 'mini',
        controls: false
      }
    ]
  },
  {
    title: '售卖限制类型',
    children: [
      { title: '原值', key: 'saleRestrictStrOld' },
      {
        title: '现值',
        render: (h, { row }) =>
          <el-select value={row.saleRestrict} size="mini" onChange={val => { row.saleRestrict = val }}>
            { SALE_RESTRICT_OPTIONS.map(item => <el-option value={item.value} label={item.label} />) }
          </el-select>
      }
    ]
  },
  {
    title: '操作',
    key: 'action',
    fixed: 'right'
  }
]

// 查看表列
export const VIEW_TABLE_COLUMNS = [
  ...BASIC_TABLE_COLUMNS,
  {
    title: '最小起售量',
    children: [
      { title: '原值', key: 'saleMinOld' },
      {
        title: '现值',
        render: (h, { row }) => generateHighlightNodeForSalePrice(h, row.saleMinOld, row.saleMin)
      }
    ]
  },
  {
    title: '售卖限制类型',
    children: [
      { title: '原值', key: 'saleRestrictStrOld' },
      {
        title: '现值',
        render: (h, { row }) => generateHighlightNodeForSalePrice(h, row.saleRestrictStrOld, row.saleRestrictStr)
      }
    ]
  }
]

// 不能编辑表列
export const NOT_EDIT_TABLE_COLUMNS = [
  ...VIEW_TABLE_COLUMNS,
  {
    title: '操作',
    key: 'action',
    fixed: 'right'
  }
]

export const FOOTER_ITEMS = [
  { label: '单据号', prop: 'recordNo' },
  { label: '审核状态', prop: 'commitStateStr' },
  { label: '提交人', prop: 'pusherName' },
  { label: '提交时间', prop: 'pushTime' },
  { label: '提交部门', prop: 'pusherDeptName' },
  { label: '区域', prop: 'pusherAreaName' },
]
